package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoCollectMember;
import com.muyu.danmo.service.IDanmoCollectMemberService;
import com.muyu.system.danmo.fegin.PayFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 拾贝会员Controller
 *
 * @author kongzong
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/danmoCollectMember")
public class DanmoCollectMemberController extends BaseController {
    @Autowired
    private IDanmoCollectMemberService danmoCollectMemberService;


    /**
     * 查询拾贝会员列表
     */
//    @RequiresPermissions("system:DanmoCollectMember:list")
    @GetMapping("/list")
    public Result list(DanmoCollectMember danmoCollectMember) {
        startPage();
        List<DanmoCollectMember> list = danmoCollectMemberService.selectDanmoCollectMemberList(danmoCollectMember);
        return Result.success(list);
    }

    /**
     * 导出拾贝会员列表
     */
//    @RequiresPermissions("system:DanmoCollectMember:export")
    @Log(title = "拾贝会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoCollectMember danmoCollectMember) {
        List<DanmoCollectMember> list = danmoCollectMemberService.selectDanmoCollectMemberList(danmoCollectMember);
        ExcelUtil<DanmoCollectMember> util = new ExcelUtil<DanmoCollectMember>(DanmoCollectMember.class);
        util.exportExcel(response, list, "拾贝会员数据");
    }

    /**
     * 判断是否为拾贝会员
     */
//    @RequiresPermissions("system:DanmoCollectMember:query")
    @GetMapping(value = "isMember/{id}")
    public Result getInfo(@PathVariable Long id) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        if (loginUser.getUserid().equals(id)){
            return Result.success(danmoCollectMemberService.selectDanmoCollectMemberById(id),"false");
        }
        return Result.success(danmoCollectMemberService.selectDanmoCollectMemberById(id),"true");
    }
    /**
     * 新增拾贝会员
     */
//    @RequiresPermissions("system:DanmoCollectMember:add")
    @Log(title = "拾贝会员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody DanmoCollectMember danmoCollectMember) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        danmoCollectMember.setUserId(loginUser.getUserid());
        return danmoCollectMemberService.insertDanmoCollectMember(danmoCollectMember);
    }

    /**
     * 修改拾贝会员
     */
//    @RequiresPermissions("system:DanmoCollectMember:edit")
    @Log(title = "拾贝会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoCollectMember danmoCollectMember) {
        return Result.success(danmoCollectMemberService.updateDanmoCollectMember(danmoCollectMember));
    }

    /**
     * 删除拾贝会员
     */
//    @RequiresPermissions("system:DanmoCollectMember:remove")
    @Log(title = "拾贝会员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return Result.success(danmoCollectMemberService.deleteDanmoCollectMemberByIds(ids));
    }


    /**
     * 查询是否为会员
     */
    @PostMapping("/selectIsShow")
    public Result selectIsShow() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        Long id = loginUser.getUserid();
        return Result.success(danmoCollectMemberService.selectIsShow(id));
    }


}
